home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / DEC8OUT < prev    next >
Encoding:
Text File  |  1985-12-22  |  1.9 KB  |  76 lines

  1. ;-------------------------dec8out routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 59
  4. ;
  5. ; NAME DEC8OUT
  6. ; ROUTINE FOR Conversion from 8-bit Binary to ASCII decimal
  7. ;
  8. ; FUNCTION: This routine accepts a 8-bit binary number in the DL register
  9. ; and converts it to ASCII decimal form which is sent to the std input
  10. ; device.
  11. ;
  12. ; INPUT: Upon entry an 8-bit binary number is in DL
  13. ; OUTPUT: A string of ASCII digits representing a decimal number is
  14. ; stored in a buffer called TBUFF and then sent out through the std output
  15. ; device.
  16. ; REGISTERS USED:  No registers are modified.  DL is used for input.
  17. ; SEGMENTS REFERENCED:  DATAS is a data segment which contains TBUFF.
  18. ; ROUTINES CALLED:  STDOUT
  19. ; SPECIAL NOTES: None
  20. ;
  21. ; ROUTINE TO CONVERT FROM INTERNAL 8-BIT BINARY TO ASCII DECIMAL.
  22. ;
  23. dec8out    proc    far
  24. ;
  25.     push    ds        ; save registers
  26.     push    di
  27.     push    dx
  28.     push    cx
  29.     push    ax
  30. ;
  31.     mov    ax,datas    ; point to the data segment
  32.     mov    ds,ax
  33. ;
  34. ; binary number is in DL
  35. ;
  36. ; Put the digits in a buffer
  37. ;
  38.     mov    cx,0        ; initialize a counter
  39.     mov    di,offset tbuff ; point to a buffer
  40. ;
  41. dec8out1:
  42.     push    cx        ; save the count
  43.     mov    al,dl        ; AX has the numerator
  44.     mov    ah,0        ; clear upper half
  45.     mov    cl,10        ; divisor of 10
  46.     div    cl        ; divide
  47.     mov    dl,al        ; get quotient
  48.     mov    al,ah        ; get remainder
  49. ;
  50.     add    al,30h        ; increase to ASCII
  51.     mov    [di],al        ; put in tbuff
  52.     inc    di        ; point to next byte
  53. ;
  54.     pop    cx        ; restore count
  55.     inc    cx        ; count the digit
  56.     cmp    dl,0        ; done ?
  57.     jnz    dec8out1
  58. ;
  59. ; dump tbuff out
  60. ;
  61. dec8out2
  62.     dec    di        ; back up through the tbuff
  63.     mov    al,[di]        ; get the byte from the tbuff
  64.     call    stdout        ; send it
  65.     loop    dec8out2
  66. ;
  67.     pop    ax        ; restore registers
  68.     pop    cx
  69.     pop    dx
  70.     pop    di
  71.     pop    ds
  72.     ret            ; return
  73. ;
  74. dec8out    endp
  75. ;-------------------------dec8out routine ends---------------------------+
  76.